/*
 * WiiPingPongController.java
 *
 *  Copyright (c) 2008 Corey Oliver and Anshul Kumaria
 *
 *  This file is part of Balls of Fury.
 *
 *  Balls of Fury is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Balls of Fury is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 *
 */

/*
 * EDIT:  03/13/2008 - This is an example of how an edit performed to the class 
 * would appear.
 */
package ballsoffury.input.wiicontrollers;

import ballsoffury.input.*;
import wiiremotej.WiiRemote;
import wiiremotej.WiiRemoteExtension;
import wiiremotej.event.WRStatusEvent;
import wiiremotej.event.WRButtonEvent;
import wiiremotej.event.WRIREvent;
import wiiremotej.event.WRExtensionEvent;
import wiiremotej.event.WRAccelerationEvent;
import wiiremotej.IRMouse;
import ballsoffury.input.WiiRemoteManager;

/**
 * An implementation of <code>WiiController</code> that controls actions that 
 * occur as a result to button pushes, and movement of the wiimote it is 
 * attached to for Balls of Fury.
 *
 * @author Corey Oliver
 * @version $Revision:$ $Date:$
 */
public class WiiPingPongController extends WiiController {
    
    WiiRemote remote;
    
    public void attachWiiRemote(WiiRemote remote) {
        this.remote = remote;
        try {
            remote.setMouse(IRMouse.getDefault());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.out.println("Controller created.");
    }
    
    public void disconnected() {
        WiiRemoteManager.removeWiiRemote(remote);
        System.out.println("Remote disconnected... Please Wii again.");
    }

    public void statusReported(WRStatusEvent evt) {
        System.out.println("Battery level: " + (double) evt.getBatteryLevel() / 2 + "%");
        System.out.println("Continuous: " + evt.isContinuousEnabled());
        System.out.println("Remote continuous: " + remote.isContinuousEnabled());
    }

    public void IRInputReceived(WRIREvent evt) {
    }

    public void accelerationInputReceived(WRAccelerationEvent evt) {
        //controllerBase.accelerationInputReceived(evt);
    }

    public void extensionInputReceived(WRExtensionEvent evt) {
    }

    public void extensionConnected(WiiRemoteExtension extension) {
        System.out.println("Extension connected!");
        try {
            remote.setExtensionEnabled(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void extensionPartiallyInserted() {
        System.out.println("Extension partially inserted.");
    }

    public void extensionUnknown() {
        System.out.println("Extension unknown.");
    }

    public void extensionDisconnected(WiiRemoteExtension extension) {
        System.out.println("Extension disconnected.");
    }

    public void buttonInputReceived(WRButtonEvent evt) {
            
            if (evt.wasPressed(WRButtonEvent.A)) {
                System.out.println("A Pressed.");
            }
            if (evt.wasPressed(WRButtonEvent.B)) {
            }
            if (evt.wasPressed(WRButtonEvent.DOWN)) {
            }
            if (evt.wasPressed(WRButtonEvent.HOME)) {
            }
            if (evt.wasPressed(WRButtonEvent.LEFT)) {
            }
            if (evt.wasPressed(WRButtonEvent.MINUS)) {
            }
            if (evt.wasPressed(WRButtonEvent.ONE)) {
            }
            if (evt.wasPressed(WRButtonEvent.PLUS)) {
            }
            if (evt.wasPressed(WRButtonEvent.RIGHT)) {
            }
            if (evt.wasPressed(WRButtonEvent.TWO)) {
            }
            if (evt.wasPressed(WRButtonEvent.UP)) {
            }
        }
    }
